<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>账户密码登录</title>
    <meta charset="UTF-8">
    <title>账户密码登录</title>
    <meta name="keywords" content="账户密码登录"/>
    <meta name="description" content="账户密码登录"/>
    <meta name="viewport" content="width=device-width,initial-scale=1, maximum-scale=1,minimum-scale=1, user-scalable=no">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width,viewport-fit=cover">
    <meta name="_csrf" th:content="${_csrf.token}"/>
    <meta name="_csrf_header"  th:content="${_csrf.headerName}"/>
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/public.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/publicOfuser.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/loginbypassword.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/combtn.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/shoppingApi/css/weui.min.css}">
    <script type="text/javascript" th:src="@{/shoppingApi/js/jquery-3.3.1.min.js}"></script>
    <!--<script type="application/javascript" th:src="@{/shoppingApi/js/common.js}"></script>-->
    <script type="text/javascript" th:src="@{/shoppingApi/js/jquery-weui.min.js}"></script>
</head>

<body>
<div class="main login bgfff">
    <!--<div class="goback fixed-back"><h3 onclick="location.href='/wap/openUserCenter'">账号登陆</h3></div>-->
    <div class="main_con c323232">

        <div class="header">
        </div>

        <div class="mt55 ml15 mr15">

            <ul class="login-form">
                <li>

                    <div class="clearfix input_border_bottom_normal">
                        <img class="ml15 fl form-icon" th:src="@{/shoppingApi/images/login_by_account.png}"
                             style="height: 22px;">
                        <div class="overflow pr15 pl15">
                            <input class="ft18 c323232  w100 userNO form-input" name="userNO" value="" placeholder="请输入用户名" type="text">
                        </div>
                    </div>
                    <p class="userNo-span"><span style='color: red;font-size: 14px'></span></p>
                </li>

                <li>

                    <div class="clearfix mt20 input_border_bottom_normal">

                        <img class="ml15 fl form-icon" th:src="@{/shoppingApi/images/login_by_account_normal.png}"
                             style="height: 22px;">
                        <a class="pinkbtn  button pink bigrounded fr forget-pwd">忘记密码</a>

                        <div class="overflow pr15 pl15">
                            <input class="ft18 c323232  w100 LoginPwd form-input" autocomplete="off" name="" value="" placeholder="请输入密码" type="text" onfocus="this.type='password'">
                        </div>
                    </div>
                    <p class="loginPwd"><span  style='color: red;font-size: 14px'></span></p>
                </li>

                <li>
                    <div><a class="submit mt40 bigrounded button red  loginByUserNO">登录</a></div>
                </li>
                <p class="login-submit"><span class="login-msg"  style='color: red;font-size: 14px'></span></p>
                <!--<li>-->
                    <!--<div class="mt15 ml15" style="line-height:24px;">-->
                        <!--&lt;!&ndash;<p>&ndash;&gt;-->
                        <!--&lt;!&ndash;<div class="fl">&ndash;&gt;-->
                            <!--<label class="agree-checkbox checked">-->
                                <!--<input type="checkbox" checked="checked" style="display:none">-->
                                <!--<span class="ml10 ft12 c323232">登录即代表您已同意</span>-->
                            <!--</label>-->
                        <!--&lt;!&ndash;</div>&ndash;&gt;-->
                        <!--<a class="ft12 cf70029">《新零售微店用户协议》</a>-->
                        <!--&lt;!&ndash;</p>&ndash;&gt;-->
                    <!--</div>-->
                <!--</li>-->
                <li>
                    <div class="mt30 ft13 ml15 mr15">
                        <a class="LoginByphone c646464"><span>手机号登录</span></a>
                        <a class="register c646464"><span class="fr">注册</span></a><br/>

                        <!--<a onclick="test()">测试跨域</a>-->

                    </div>
                </li>
            </ul>
        </div>
    </div>
</div>
</body>
<script type="application/javascript">

// function  test() {
//     $.ajax({
//
//         url:"http://localhost:8086/wap/getDetailsSpecListByGoodsId?Id=1",
//         success:function (res) {
//             console.log(res);
//         }
//     })
// }




    // $(function () {
    //     history.pushState({page: 1}, 'title', '/wap/openUserCenter');
    // });
    /*请求头定义*/
    var header = $("meta[name='_csrf_header']").attr("content");
    var token =$("meta[name='_csrf']").attr("content");

    $('.register').on('click',function () {
        window.location.href="/wap/openRegister"
    })

    //用户名
    function getUserNO() {
        var userNo=$(".userNO").val();
        if(userNo==""){
            $(".userNo-span span").html("用户号不能为空");
            return "";
        }else{
            return userNo;
        }
    }

    //密码
    function  getPwd() {
        var pwd=$('.LoginPwd').val();
        if(pwd==""){
            $('.loginPwd span').html("密码不能为空");
            return "";
        }else{
            return pwd;
        }
    }
    $.toast.prototype.defaults.duration = 1000;
   $('.loginByUserNO').on('click',function () {
        var userNo= getUserNO();
        var pwd=getPwd();
        if(userNo!=""&&pwd!=""){
            $.ajax({
                type:'post',
                url:"/wap/loginByPwd",
                data:{
                    userNo:userNo,
                    pwd:pwd,
                },
                success:function (result) {
                    if(result.msg=="000000"){
                        $('.loginPwd span').text('登录用户名或密码错误');
                        $(".userNo-span").remove();
                    }else if(result.msg=="000001"){
                        $.toast("登录成功");
                        var userNoId = result.userNo.id.toString();
                        var redirect = location.href.split('?redirect=')[1];
                        if (redirect) {
                            var url = decodeURIComponent(redirect);
                        } else {
                            // var url = '/wap/openUserCenter';
                             var url = '/wap/productIndex';
                            // var url = '/wap/activity?productId=490';
                        }
                        if(navigator.userAgent.indexOf("Html5Plus") > -1){
                            var pageIndex = plus.webview.getWebviewById('__W2A__www.ycsqd.com');
                            // var pageDetail = plus.webview.getWebviewById('detail');
                            plus.storage.setItem('userNoId', userNoId);
                            setTimeout(function () {
                                location.href = url;
                            }, 1000);
                            // alert(plus.storage.getItem('userNoId'));
                            pageIndex.reload();
                            // pageDetail.reload();
                            // mui.back();
                        } else {
                            localStorage.setItem('userNoId', userNoId);
                            location.href = url;
                        }

                    }else{
                        $('.loginPwd span').text('登录用户名或密码错误');
                        $(".userNo-span").remove();
                    }
                },
                beforeSend : function(xhr) {
                    xhr.setRequestHeader(header, token);
                }
            })
        }
   })

   $('.LoginByphone span').on('click',function () {
       var redirect = location.href.split('?redirect=')[1],
           url = "/wap/openLoginByPhone";
       if (redirect) {
           url = url + '?redirect=' + redirect;
       }
       window.location.href=url;
   })

    //失去焦点验证用户号是否存在
    $('.userNO').on('blur', function () {
        validateUser(false);
    });

    //忘记密码
    $('.forget-pwd').on('click',function () {
        validateUser(true);
    });
    function validateUser (flag) {
        var userNo=$('.userNO').val();//用户编号
        var str=userNo.substring(0,1).toLowerCase();
        var reg = /^[a-zA-Z0-9]{4,20}$/i.test(userNo);
        if(reg){
            $.ajax({
                url:"/wap/selectUserNoByUserNo?userNo="+userNo,
                success:function (result) {
                    console.log(result.userNo);
                    if(result.userNo){
                        if (flag) {
                            window.location.href ="/wap/forgetPwd?userNo="+userNo;
                        } else {
                            $(".userNo-span span").html("");
                        }
                    }else {
                        $(".userNo-span span").html("请输入正确的用户号").css('color', 'red');
                    };
                },
                error: function (err) {
                    console.log(err);
                    $(".userNo-span span").html("请输入正确的用户号").css('color', 'red');
                }
            })
        }else{
            $(".userNo-span span").html("请输入正确的用户号");
        }
    }
    $('.agree-checkbox').on('click', function (e) {
        if (!$(this).hasClass('checked')) {
            $(this).addClass('checked');
        } else {
            $(this).removeClass('checked');
        }
        e.preventDefault();
    });
</script>

</html>